var home = {
    notice_num: 0,
    //竞拍列表
    goodList: function (type, p) {
        var area_code =  $.getSession('area_code')?$.getSession('area_code'):null;
        $('.load-box').children('b').text('加载中');
        $('.load-box').children('span').show()
        $('.load-box').show();
        var data = {
            auctionType: type,
            categroyId: null,
            areaCode: area_code,
            auctionStatus: null,
            orderField: null,
            orderDirection: null,
            keyword: null,
            pageNum: p,
            pageSize: CONFIG.pageSize,
        };
        $.commonAjax({
            url: "B058",
            type: "GET",
            openDialog: false,
            data: data,
            isShowError: true,
            success: function (res) {
                var htm = '';
                $.each(res.data.data, function (k, item) {
					//var goodsCode = item.goods.iconImages.goodsCode;
					console.log(item);
                    htm += '<div onClick="bp.jump_data(\'details.html?auctionCode='+item.code+'&goodsCode='+item.goods.code+'\');" class="con-list">'
                    htm += '    <div class="shopImg">'
                    htm += '        <img src="' + (item.goods.iconImages ? CONFIG.imgUrl + item.goods.iconImages.mediumUrl : '') + '" alt="">'
                    htm += '    </div>'
                    htm += '    <div class="shopInfo">'
                    htm += '        <div class="shopTit">' + item.name + '</div>'
                    htm += '        <div class="money-info">'
                    var price = 0;
                    var price_show = ''
                    switch (item.status) {
                        case 1: price = item.finish_price==null?0:item.finish_price; break;
                        case 2: price = item.currentPrice;price_show='当前价'; break;
                        case 4: price =  item.finish_price==null?0:item.finish_price;price_show='最终价'; break;
                        case 5: price =  item.finish_price==null?0:item.finish_price;price_show='成交价'; break;
                        case 6: price = item.finish_price==null?0:item.finish_price;price_show='最终价'; break;
                        default: break;
                    }
                    htm += '            <div class="nowMoney">'+price_show+'：<span>'+price+'</span></div>'
                    var typeShow = '';
                    switch (item.type) {
                        case 1: typeShow = '竞拍交易'; break;
                        case 2: typeShow = '议价撮合'; break;
                        case 3: typeShow = '招投标'; break;
                        case 4: typeShow = '闪拍'; break;
                        default: break;
                    }
                    htm += '            <div class="business">' + typeShow + '</div>'
                    htm += '        </div>'
                    htm += '        <div class="date-info">'
                    htm += '            <div class="time ' + (item.status <= 3 ? '' : 'timeEnd') + '">' + item.statusDesc + '</div>'
                    htm += '            <div class="follow">' + item.visitCount + '次围观</div>'
                    htm += '        </div>'
                    htm += '    </div>'
                    htm += ' </div>'
                });
                p == 1 ? $('.tab-con0' ).html(htm) : $('.tab-con0').append(htm);
                if (res.data.data.length) {
                    $('.load-box').hide();
                } else {
                    $('.load-box').children('b').text('到底啦``');
                    $('.load-box').children('span').hide();
                }
            }, error: function (res) {
                $.layermsg(res.msg);
                $('.load-box').hide();
            }
        });
    },
    //轮播
    banner: function () {
        var data = { client: 'wecahrt', type: 'banner' }
        $.commonAjax({
            url: 'B001',
            type: 'GET',
            data: data,
            isShowError: true,
            success: function (res) {
                var htm = '';
                $.each(res.data, function (k, v) {
                    if (v.imageUrl != null) {
                        if (v.linkUrl != null) {
                            htm += '<div class="swiper-slide"><img onClick="bp.jump(\'' + v.linkUrl + '\')" src="' + CONFIG.imgUrl + v.imageUrl + '" alt=""></div>';
                        } else {
                            htm += '<div class="swiper-slide"><img onClick="bp.jump(\'' + v.linkUrl + '\')" src="' + CONFIG.imgUrl + v.imageUrl + '" alt=""></div>';
                        }
                    }
                });
				$('#banner').html(htm);
                var swiper = new Swiper('.swiper-container', {
                    pagination: '.swiper-pagination',
                    paginationClickable: true,
                    autoplay: 5000,
                    autoplayDisableOnInteraction: false,
                    loop: true
                });
            }, error: function (res) {
                $.layermsg(res.msg);
            }
        });
    },
    notice: function () {
        var data = {};
        $.commonAjax({
            url: 'B005',
            type: 'GET',
            data: data,
            isShowError: true,
            success: function (res) {
                home.noticeShow(res.data);
            }, error: function (res) {
                $.layermsg(res.msg);
            }
        });
    }, noticeShow: function (data) {
        var htm = '';
        $.each(data, function (k, v) {
            htm += '<li class="roll-list">';
            htm += '    <div class="notice-tit">' + v.name + '</div>';
            htm += '    <div class="notice-date">发表日期:' + bp.timestamp_to_date(Number(v.createTime)) + '</div>';
            htm += '</li>';
        });
        $('#gg').html(htm);
        var step = $(".roll-list").height();
        setInterval(function () {
            $(".roll-box").find(".roll-ul:first").animate({
                marginTop: "-" + step
            }, 1000, function () {
                $(this).css({ marginTop: "0px" }).find(".roll-list:first").appendTo(this);
            });
        }, 1500);
    },
    //公示商品
    publicity: function () {
        var data = {};
        $.commonAjax({
            url: 'B004',
            type: 'GET',
            data: data,
            isShowError: true,
            success: function (res) {
                if(!res.data[0]){
                    $('.publicity').hide();
                    return false;
                }
                var htm = ''
                $.each(res.data, function (k, v) {
					if(k<2){
						htm += '<div  onClick="bp.jump_data(\'details.html?auctionCode='+v.code+'&goodsCode='+v.goods.code+'\');"   class="publicity-list">';
						htm += '    <div class="publicityImg">';
						htm += '        <img src="' + CONFIG.imgUrl + v.goods.iconImages.mediumUrl + '" alt="">';
						htm += '    </div>';
						htm += '    <div class="info-box">';
						htm += '        <div class="tit">' + v.name + '</div>';
						htm += '        <div class="bond">保证金：<span>￥' + v.marginAmount + '</span></div>';
						htm += '        <div class="date">开始日期:<span>' + bp.timestamp_to_date(Number(v.createTime), 1) + '</span></div>';
						htm += '    </div>';
						htm += '</div>';
					}
                });
                $('.publicity-info').html(htm);
                if (layer) {
                    layer.closeAll();
                }
            }, error: function (res) {
                $.layermsg(res.msg);
            }
        })
    }
}

var p = 1;
var list_type = 1;
var getPage = function () {
    p = p + 1;
    home.goodList(list_type, p);
}
$(function () {
    var area_name = $.getSession('area_name');
    if(area_name){
        $('.location').text(area_name);
    }
    $(window).load(function () {
        home.banner();
    });
    $(window).load(function () {
        home.notice();
    })
    $('.search').click(function(){
        var val = $('.search-ipt').val();
        if(val.length){
            bp.jump_data('shopList.html?keyword='+val);
        }   
    });
    home.publicity();
    home.goodList(1, 1);
    $('li[id^="goodList_"]').click(function () {
        var idx = $(this).index();
        $(this).addClass("nav-list-active").siblings().removeClass("nav-list-active");
        //$('div[class^="tab-con"]').hide();
       // $(".tab-con" + idx).show();
        var type = list_type = $(this).prop('id').split('_')[1];
        list_type = type;
        p = 1;
        home.goodList(type, 1);
    });
    bp.waterfall();

    /*侧边的控制*/
    $(window).scroll(function () {
        var sTop = $(document).scrollTop();
        if (sTop > 100) {
            $(".aside-box").show();
        } else if (sTop < 100) {
            $(".aside-box").hide();
        }
    });

    /*回到顶部*/
    $(".goTopIcon").click(function () {
        $(document).scrollTop(0);
    });

    
})